# -*- coding: utf-8 -*-
# https://blog.csdn.net/weixin_52040868
# 公众号：测个der
# 微信：qing_an_an


import sys
from PyQt5.QtWidgets import *
from PyQt5.Qt import *
from PyQt5.QtCore import *


global sec
sec = 0

class WorkThread(QThread):
    trigger = pyqtSignal()
    def __init__(self):
        super(WorkThread, self).__init__()

    def run(self) -> None:
        for i in range(2000000000):
            pass
        # 循环完成发射信号
        self.trigger.emit()

def countTime():
    global  sec
    sec += 1
    # LED显示数字
    lcdNumber.display(sec)

def work():
    # 读秒时间间隔
    timer.start(1000)
    # 计时开始
    workthread.start()
    # 获取循环完毕的信号时，停止计数
    workthread.trigger.connect(timeStop)

def timeStop():
    timer.stop()
    print("运行结束用时",lcdNumber.value())
    global sec
    sec = 0

if __name__ == '__main__':
    app = QApplication(sys.argv)
    top = QWidget()
    top.resize(300,120)

    # 垂直布局
    layout = QVBoxLayout(top)
    # 添加一个显示版
    lcdNumber = QLCDNumber()
    button = QPushButton("测试")
    layout.addWidget(button)
    layout.addWidget(lcdNumber)

    timer = QTimer()
    workthread = WorkThread()
    button.clicked.connect(work)
    # 每次即时结束，触发countTime
    timer.timeout.connect(countTime)

    top.show()
    sys.exit(app.exec_())